<template>
  <div class="autoapply">
    <navBar title="一键提交" @onClickLeft="onClickLeft" />
    <div class="zlxt-list">
      <van-list
        v-model="control.loading"
        :finished="control.finished"
        @load="onLoad"
      >
      <template #finished>
        <span v-if="show.active==0">没有您想要报销的专利？<a style="color:blue" href='tel://13237126506'>联系客服</a></span>
        <span v-else>找不到您已申请报销的专利？<a style="color:blue" href='tel://13237126506'>联系客服</a></span>
      </template>
        <van-search v-model="show.searchValue" @clear="clearSerch" @input="serchNull" @search="sendSearch" placeholder="请输入案件名称" />
        <van-tabs v-model="show.active" @change="tabsChange">
          <van-tab title="可报销"></van-tab>
          <van-tab title="报销中"></van-tab>
        </van-tabs>
        <div class="item" v-for="(item, index) in show.list" :key="index">
          <van-cell
            :title="item.patentApplication_number || item.application_number"
            size="large"
            @click='goUploadPatent(item)'
          >
            <template #label>
              <span  class="font12">{{ item.patentName || item.name }}</span>
            </template>
            <template #default>
              <span class="font12">{{ item.patentPatent_user || item.patent_user }}</span>
            </template>
          </van-cell>
        </div>
      </van-list>
    </div>
  </div>
</template>

<script>
import { Search, Toast,Dialog } from "vant";
import navBar from "@cb/navBar.vue";
import {get,post} from '../../../public/API/query'
export default {
  data() {
    return {
      show: {
        p:1,
        list: [],
        searchValue: "",
        type:1,
        active:0,
        patentSecret:""
        // message:`没有您想要报销的专利？<a href='tel://13237126506'>联系客服</a>`
      },
      control: {
        isSend:false,
        loading: false,
        finished: false
      }
    };
  },
  components: {
    navBar
  },
  created(){
    this.show.patentSecret = this.$route.query.patentSecret
  },
  methods: {
    tabsChange(value){
      value == 0 ? this.show.type = 1 : this.show.type = 2
      this.show.p = 1
      this.show.list = []
      this.onLoad()
    },
    serchNull(){
      if (this.show.searchValue == "") {
        this.show.p = 1
        this.show.list = []
        this.onLoad()
      }
    },
    clearSerch(){
      this.show.p = 1
      this.show.searchValue = ""
      this.show.list = []
      this.onLoad()
    },
    sendSearch(){
      if (this.control.isSend) {
        Toast('请稍后再试...')
        return false
      }
      this.show.p = 1
      this.show.list = []
      console.log(this.show.list)
      this.onLoad()
    },
    onClickLeft() {
      this.$router.push('/user');
    },
    onLoad() {
      this.control.loading = true;
      this.control.finished = false;
      this.getData();
      this.show.p++;
    },
    getData(){
      if (this.control.isSend) {
        return false
      }
      this.control.isSend = true
      let params = {
        p:this.show.p,
        type:this.show.type,
      }
      this.show.patentSecret?params.patentSecret = this.show.patentSecret:""
      if (this.show.searchValue) {
        params.title = this.show.searchValue
      }
      get('sysPatentList',params,res=>{
        this.control.isSend = false
        if(res.code == 200){
          this.show.list = this.show.list.concat(res.data._list)
          this.control.loading = false;
          if (res.data._list.length < 15) {
            this.control.finished = true;
          }else{
            this.control.finished = false;
          }
        }else {
          this.control.loading = false;
          this.control.finished = true;
        }
      })
    },
    goUploadPatent(item) {
      if(this.show.active==0){
        this.$router.push({
          path: `/user/uploadPatent`,
          query: {
            id: item.id,
            patentSecret:this.show.patentSecret
          }
        });
      }
        
    }
  }
};
</script>

<style style="less" scope='scoped'>
/* .no_warp{
  white-space: nowrap;
  text-overflow:ellipsis;
  overflow: hidden;
} */
.font12{
    font-size:12px;
}

</style>
